package com.lucifer.hawkeye.ai.domain.conversation.type;

import lombok.Getter;
import org.apache.commons.collections4.map.UnmodifiableMap;

import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author lucifer
 * @date 2025/4/1 14:29
 */
@Getter
public enum ConversationType {

    // 对话类型
    T2T("T2T","New Chat"),
    // 自然语言转SQL
    NL2SQL("NL2SQL","NL2SQL"),;

    private final String code;
    private final String name;

    private static final Map<String, ConversationType> CODE_MAPPING = UnmodifiableMap.unmodifiableMap(
            Arrays.stream(ConversationType.values()).collect(Collectors.toMap(ConversationType::getCode, Function.identity()))
    );


    public static boolean check(String code) {
        return CODE_MAPPING.containsKey(code);
    }


    public static ConversationType codeOf(String code) {
        return Optional.ofNullable(code).map(CODE_MAPPING::get).orElse(ConversationType.T2T);

    }

    ConversationType(@NotNull String code, @NotNull String name) {
        this.code = code;
        this.name = name;
    }
}
